﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ImobitechModel.com.Constantes;
using ImobitechModel.com.Controller;

namespace Imobitech.Anuncio
{
    public partial class editaAnuncio : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                hdnId.Value = Request.QueryString["id"];
                IDictionary<string, string> plan = new Dictionary<string, string>();
                plan.Add(NomeCampoConstantes.campo_planId, hdnId.Value);

                ControladorPlan cg = new ControladorPlan();

                IDictionary<string, string> values = (IDictionary<string, string>)cg.retornaPlano(plan);

                txtName.Text = values.First(p => p.Key == NomeCampoConstantes.campo_planName).Value;
                double receber = 0;
                double.TryParse(values.First(p => p.Key == NomeCampoConstantes.campo_planValue).Value, out receber);
                txtValue.Text = receber.ToString();
                txtDtStart.Text = values.First(p => p.Key == NomeCampoConstantes.campo_planDateStart).Value;
                
                txtDtFinish.Text = values.First(p => p.Key == NomeCampoConstantes.campo_planDateFinish).Value;
            }
            
        }

        protected void btnEditar_Click(object sender, EventArgs e)
        {
            IDictionary<string, string> plan = new Dictionary<string, string>();
            plan.Add(NomeCampoConstantes.campo_planName, txtName.Text);
            plan.Add(NomeCampoConstantes.campo_planValue, txtValue.Text);
            plan.Add(NomeCampoConstantes.campo_planDateStart, txtDtStart.Text);
            plan.Add(NomeCampoConstantes.campo_planDateFinish, txtDtFinish.Text);
            plan.Add(NomeCampoConstantes.campo_planId, hdnId.Value);

            ControladorPlan cg = new ControladorPlan();

            Object objeto = cg.editaPlan(plan);
        }

        protected void btnCancelar_Click(object sender, EventArgs e)
        {
            Response.Redirect("ListaPlano.aspx");
        }
    }
}